package com.dms.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.dms.dao.TBDao;
import com.dms.model.TB;

@Repository
public class TBDaoImpl extends BaseDaoImpl implements TBDao {

	@Override
	public TB getTB(String hql) {	
		return (TB) getSession().createQuery(hql).uniqueResult();
	}

	@Override
	public void updateTB(TB tb) {
		Session session=this.getSession();
		session.merge(tb);
		session.flush();
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<TB> getTBs(String hql) {
		return getSession().createQuery(hql).list();
	}

	@Override
	public void save(TB tb) {
		this.getSession().save(tb);
		
	}

	@Override
	public void delete(int tId, int bId) {
		Session session=getSession();
		String hql="from TB where building.id="+bId+
				" and teacher.id="+tId;
		TB tb=(TB) session.createQuery(hql).uniqueResult();
		session.delete(tb);
		session.flush();
	}
}
